4c3da03abd8feaa018ff1685fa03fcfbe5e5c46d,src/freenet/client/async/SplitFileFetcherStorage.java,SplitFileFetcherStorage,SplitFileFetcherStorage,#LockableRandomAccessThing#boolean#SplitFileFetcherStorageCallback#FetchContext#RandomSource#PersistentJobRunner#KeysFetchingLocally#Ticker#MemoryLimitedJobRunner#ChecksumChecker#boolean#KeySalter#boolean#boolean#,594
Before Change
this.completeViaTruncation = completeViaTruncation;
// FIXME this is hideous! Rewrite the writing/parsing code here in a less ugly way. However, it works...
rafLength = raf.size();
if(raf.size() < 8 /* FIXME more! */)
throw new StorageFormatException("Too short");
// Last 8 bytes: Magic value.
byte[] buf = new byte[8];
raf.pread(rafLength-8, buf, 0, 8);
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf));
if(dis.readLong() != END_MAGIC)
throw new StorageFormatException("Wrong magic bytes");
// 4 bytes before that: Version.
byte[] versionBuf = new byte[4];
raf.pread(rafLength-12, versionBuf, 0, 4);
dis = new DataInputStream(new ByteArrayInputStream(versionBuf));
int version = dis.readInt();
if(version != 1)
throw new StorageFormatException("Wrong version "+version);
// 2 bytes: Checksum type
byte[] checksumTypeBuf = new byte[2];
raf.pread(rafLength-14, checksumTypeBuf, 0, 2);
dis = new DataInputStream(new ByteArrayInputStream(checksumTypeBuf));
int checksumType = dis.readShort();
if(checksumType != ChecksumChecker.CHECKSUM_CRC)
throw new StorageFormatException("Unknown checksum type "+checksumType);
// 4 bytes: Flags. Unused at present.
byte[] flagsBuf = new byte[4];
raf.pread(rafLength-18, flagsBuf, 0, 4);
dis = new DataInputStream(new ByteArrayInputStream(flagsBuf));
int flags = dis.readInt();
if(flags != 0)
throw new StorageFormatException("Unknown flags: "+flags);
// 4 bytes basic settings length and a checksum, which includes both the settings length and the version.
buf = new byte[14];
raf.pread(rafLength-(22+checksumLength), buf, 0, 4);
byte[] checksum = new byte[checksumLength];
// Check the checksum.
raf.pread(rafLength-(18+checksumLength), checksum, 0, checksumLength);
System.arraycopy(flagsBuf, 0, buf, 4, 4);
System.arraycopy(checksumTypeBuf, 0, buf, 8, 2);
System.arraycopy(versionBuf, 0, buf, 10, 4);
if(!checksumChecker.checkChecksum(buf, 0, 14, checksum))
throw new StorageFormatException("Checksum failed on basic settings length and version");
dis = new DataInputStream(new ByteArrayInputStream(buf));
After Change
this.completeViaTruncation = completeViaTruncation;
// FIXME this is hideous! Rewrite the writing/parsing code here in a less ugly way. However, it works...
rafLength = raf.size();
if(raf.size() < 8 /* FIXME more! */)
throw new StorageFormatException("Too short");
// Last 8 bytes: Magic value.
byte[] buf = new byte[8];
raf.pread(rafLength-8, buf, 0, 8);
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf));
if(dis.readLong() != END_MAGIC)
throw new StorageFormatException("Wrong magic bytes");
// 4 bytes before that: Version.
byte[] versionBuf = new byte[4];
raf.pread(rafLength-12, versionBuf, 0, 4);
dis = new DataInputStream(new ByteArrayInputStream(versionBuf));
int version = dis.readInt();
if(version != 1)
throw new StorageFormatException("Wrong version "+version);
// 2 bytes: Checksum type
byte[] checksumTypeBuf = new byte[2];
raf.pread(rafLength-14, checksumTypeBuf, 0, 2);
dis = new DataInputStream(new ByteArrayInputStream(checksumTypeBuf));
int checksumType = dis.readShort();
if(checksumType != ChecksumChecker.CHECKSUM_CRC)
throw new StorageFormatException("Unknown checksum type "+checksumType);
// 4 bytes: Flags. Unused at present.
byte[] flagsBuf = new byte[4];
raf.pread(rafLength-18, flagsBuf, 0, 4);
dis = new DataInputStream(new ByteArrayInputStream(flagsBuf));
int flags = dis.readInt();
if(flags != 0)
throw new StorageFormatException("Unknown flags: "+flags);
// 4 bytes basic settings length and a checksum, which includes both the settings length and the version.
buf = new byte[14];
raf.pread(rafLength-(22+checksumLength), buf, 0, 4);
byte[] checksum = new byte[checksumLength];
// Check the checksum.
raf.pread(rafLength-(18+checksumLength), checksum, 0, checksumLength);
System.arraycopy(flagsBuf, 0, buf, 4, 4);
System.arraycopy(checksumTypeBuf, 0, buf, 8, 2);
System.arraycopy(versionBuf, 0, buf, 10, 4);
if(!checksumChecker.checkChecksum(buf, 0, 14, checksum))
throw new StorageFormatException("Checksum failed on basic settings length and version");
dis = new DataInputStream(new ByteArrayInputStream(buf));